from django.shortcuts import render, HttpResponse
from datetime import datetime
# Create your views here.
def index(request):
    return render(request, 'index.html')

def baidu(request):
    return render(request, 'baidu.html')

def info(request):
    # 1.普通变量
    usename = '学习课堂'
    # 2.字典类型
    book = {'name': '数据库技术', 'price': 100}
    # 3.列表
    books = [
        {
            'name': '数据库技术', 'price': 100}, {'name': 'web前端开发', 'price': 200}, {'name': 'python开发', 'price': 300}
             ]
    # 4.对象
    class Person:
        def __init__(self, realname):
            self.realname = realname
    context = {
        'usename': usename, 'book': book, 'books': books, 'person': Person('django课堂学习中')
    }
    return render(request, 'info.html', context=context)
def if_view(request):
    age = 17
    return render(request, 'if_view.html', context={'age': age})
def for_view(request):
    # 1.列表
    prices = [
        # {'name': '数据库技术', 'price': 100}, {'name': 'web前端开发', 'price': 200}, {'name': 'python开发', 'price': 300}
    ]

    # 2.渲染字典
    dire = {
        "real": 'django',
        "age": '18',
        "gender": '男',
    }
    # 字典循环三种方法
    # for x in dire.items:
    # for x in dire.keys:
    # for x in dire.values:
    # break/continue:在模版中，不存在break/continue，因为模版是展示数据，不是处理数据
    context = {'prices': prices, 'dire': dire}
    return render(request, 'for_view.html', context=context)
def with_view(request):
    context={
        'books': [{'name': '数据库技术', 'price': 100}, {'name': 'web前端开发', 'price': 200}, {'name': 'python开发', 'price': 300}]
    }
    return render(request, 'with_view.html', context=context)

def url_view(request):
    return render(request, 'url_view.html')

def book_detail(request, book_id):
    return HttpResponse(f'图书id是:{book_id}')
# 过滤器的使用
def filter_view(request):
    greet = "HEllO WORLD HELLO WORLD"
    context = {
        "greet": greet,
        'birthday':datetime.now(),
        'profile':"小时候快乐很简单，长大后开心并不一定是快乐",
        'html': "<h1>欢迎来到django课堂<h1>"
    }
    return render(request, 'filter_view.html', context=context)
# 模块继承
def template_view(request):
    context={
        'articles':['小米su7','ChatGPT 5']
    }
    return render(request, "xfz_index.html",context=context)

def static_view(request):
    return render(request, 'static.html')
